<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Data Bunker Login</title>
    <script src="conf.js"></script>
    <script src="site.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="style.css">

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.bundle.min.js"></script>
<script>
conf = loadUIConfiguration();
if (conf["custom_css_link"]) {
  document.write("<link rel='stylesheet' type='text/css' href='" + conf["custom_css_link"] +"' />");
}
</script>
</head>

<body>
    <div class="container col-md-6 pY-100">
		<script>
		conf = loadUIConfiguration();
		if (conf["LogoLink"]) {
			document.write("<center><div class='col-6'><a href='/'><img class='logo img-responsive' src='"+conf["LogoLink"]+"'></a></div></center>" );
		}
		</script>
        <div class="row">
            <div class="bigblock">
                <h4>Verification step</h4>
                <p>Enter the code you received by email or by SMS:</p>
                <form id="loginform">
                    <div class="form-group">
                        <input id="codevalue" autocomplete="off" type="login" class="form-control" placeholder="Enter..."></div>
                    <div class="form-group">
                        <div class="peers ai-c jc-sb fxw-nw">
                            <div class="peer">
                            </div>
                            <div class="peer">
				    <a href='/' class="btn btn-secondary">Cancel</a>&nbsp;&nbsp;
				    <button id="submitbtn" class="btn btn-primary">Enter</button></div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
	    <script>displayFooterLinks();</script>
    </div>
    <script>
        $('#submitbtn').on('click', function (e) {
            e.preventDefault();
            var code = $('#codevalue').val();
            var login = window.localStorage.getItem('login')
            if (login.indexOf('@') > 0) {
                $.get("/v1/login/email/" + encodeURI(login) + "/" + encodeURI(code), function (data) {
                    window.localStorage.setItem('login', "");
                    if (data.xtoken) {
                        window.localStorage.setItem('xtoken', data.xtoken);
                        window.localStorage.setItem('token', data.token);
                        document.location = getUserStartPage();
                    } else {
                        document.location = "/";
                    }
                }, "json");
            } else {
                $.get("/v1/login/phone/" + encodeURI(login) + "/" + encodeURI(code), function (data) {
                    window.localStorage.setItem('login', "");
                    if (data.xtoken) {
                        window.localStorage.setItem('xtoken', data.xtoken);
                        window.localStorage.setItem('token', data.token);
                        document.location = getUserStartPage();
                    } else {
                        document.location = "/";
                    }
                }, "json");
            }
        })
    </script>
</body>
